﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Rtgs.master" AutoEventWireup="true"
    CodeFile="sys_t_rolelist.aspx.cs" Inherits="RTGS.Web.page.usermanagement.sys_t_rolelist" %>

<%@ Register Src="~/usercontrol/searching.ascx" TagPrefix="uc" TagName="searching" %>
<asp:Content ID="ctnBody" ContentPlaceHolderID="body" runat="server">
    <link type="text/css" rel="stylesheet" href="<%= ResolveClientUrl("~/css/ui.jqgrid.css") %>" />
    <script type="text/javascript" src="<%= ResolveClientUrl("~/script/i18n/grid.locale-en.js") %>"></script>
    <script type="text/javascript" src="<%= ResolveClientUrl("~/script/jquery.jqGrid.min.js") %>"></script>
    <script src="<%= ResolveClientUrl("~/script/helper.js") %>" type="text/javascript"></script>
    <div>
        <a href="#" id="dialog_link" class="dialog_link ui-state-default ui-corner-all" alt="Add"
            onclick="OpenForm('add')"><span class="ui-icon ui-icon-plus"></span>Add</a>
        <a href="#" id="dialog_link" class="dialog_link ui-state-default ui-corner-all" alt="Edit"
            onclick="OpenForm('edit');"><span class="ui-icon ui-icon-pencil"></span>Edit</a>
        <a href="#" id="dialog_link" class="dialog_link ui-state-default ui-corner-all" alt="Delete"
            onclick="OpenForm('delete');"><span class="ui-icon ui-icon-trash"></span>Delete</a>
    </div>
    <br />
    <uc:searching ID="ucSearch" IncludeParameter="=,like" AliasField="roleName=Role"
        ClassName="sysTRole" ExcludeField="role_id, created_by, created_date, modified_by, modified_date"
        runat="server" />
    <br />
    <table id="table" class="scroll" cellpadding="0" cellspacing="0">
    </table>
    <div id="pager" class="scroll">
    </div>
    <br />
    <div id="dialog" title="Default dialog">
    </div>
    <script type="text/javascript">

        var handlerUrl = '<%= ResolveClientUrl("~/ajaxhandler/usermanagement/sys_t_role.ashx") %>';

        $('#table').jqGrid({
            url: handlerUrl + '?method=getdata',
            datatype: 'json',
            colNames: ['ID', 'Role'],
            colModel: [
           		{ name: 'roleId', hidden: true, index: 'ROLE_ID', width: 60 },
           		{ name: 'roleName', index: 'ROLE_NAME', width: 200 }
           	],
            rowNum: 10,
            id: 'ROLE_NAME',
            multiselect: true,
            rowList: [5, 10, 15, 20],
            pager: '#pager',
            sortname: 'ROLE_NAME',
            sortorder: "asc",
            viewrecords: true,
            jsonReader: { repeatitems: false },
            width: 600,
            height: '100%',
            caption: 'Role',
            ajaxGridOptions: { cache: false },
            ondblClickRow: function () {
                OpenForm('edit');
            }
        });

        function OpenForm(ctl) {

            var formUrl = '<%= ResolveClientUrl("~/form/usermanagement/sys_t_roleform.aspx") %>';

            var grid = $('#table');
            var selIds = grid.jqGrid('getGridParam', 'selarrrow'),
                selText = [];
            $.each(selIds, function () {
                selText.push(grid.jqGrid('getCell', this, 'roleId'));
            });

            if (ctl == 'edit') {
                $('#dialog').load(formUrl + '?id=' + selText).dialog({ modal: true, width: 450, title: 'Edit Role' });
            }
            else if (ctl == 'add') {
                $('#dialog').load(formUrl).dialog({ modal: true, width: 450, title: 'Add Role' });
            }
            else {
                var result = window.confirm('Are you sure that you want to delete?');
                if (result) {
                    CallAjax('<%= ResolveClientUrl("~/ajaxhandler/usermanagement/sys_t_role.ashx") %>', "?method=delete" + "&id=" + selText);

                    setTimeout("$('#table').trigger('reloadGrid');", 3000);
                }
            }

        }
    
    </script>
    <script type="text/javascript">

        $('#btnSearch').click(function () {

            var field = $('#<%= ucSearch.ClientID %>_ddlField').val();
            var operand = $('#<%= ucSearch.ClientID %>_ddlOperand').val();
            var value = $('#<%= ucSearch.ClientID %>_txtValue').val();

            var handlerUrl = '<%= ResolveClientUrl("~/ajaxhandler/usermanagement/sys_t_role.ashx") %>';

            $('#table').jqGrid('setGridParam', {
                url: handlerUrl + '?method=getdata' + '&field=' + field + '&operand=' + operand + '&value=' + value
            }).trigger('reloadGrid', [{ page: 1}]);

            return false;

        });
    
    </script>
</asp:Content>
